﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;


namespace DATA_SERVER
{
    class Net_Func
    {
        private static Socket UDPSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

        public static bool SendTCP(Byte[] bSendData, IPEndPoint RemoteEP)
        {
            try
            {
                Socket TCPSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                TCPSocket.Connect(RemoteEP);
                TCPSocket.Send(bSendData, bSendData.Length, 0);
                TCPSocket.Close();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public static bool SendUDP(Byte[] bSendData, IPEndPoint RemoteEP)
        {
            try
            {
                UDPSocket.SendTo(bSendData, bSendData.Length, 0, RemoteEP);
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
